package com.ming.controller;



import com.ming.pojo.AccessRecord;
import com.ming.service.impl.AccessRecordServiceImpl;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/record")
public class AccessRecordController {

    @Autowired
    public AccessRecordServiceImpl recordService;

    /**
     * 车辆进入小区
     * @param carLicenseId
     * @return isInterior
     */
    @RequestMapping("/enter")
    public boolean enter(String carLicenseId) {
        return recordService.addEnter(carLicenseId);
    }

    /**
     * 车辆离开小区
     * @param carLicenseId
     * @return expense
     */
    @RequestMapping("/leave")
    public AccessRecord leave(String carLicenseId) {
        return recordService.addLeave(carLicenseId);
    }

    /**
     * 出入记录列表
     * @return
     */
    @RequestMapping("/recordsList")
    public List<AccessRecord> recordsList() {
        return recordService.allList();
    }

    /**
     *  搜索出入记录通过车牌
     * @param carLicenseId
     * @return
     */
    @RequestMapping("/recordsCarId")
    public List<AccessRecord> recordsCarId(String carLicenseId) {
        return recordService.listByCarId(carLicenseId);
    }

    /**
     * 点击按钮切换内外车记录
     * @param isInterior
     * @return
     */
    @RequestMapping("/recordsInterior")
    public List<AccessRecord> recordsInterior(boolean isInterior) {
        return recordService.listByInterior(isInterior);
    }

    @PostMapping("/addRecord")
    public void addRecord(@RequestBody AccessRecord accessRecord) {
        recordService.addRecord(accessRecord);
    }

    @PostMapping("/deleteRecord")
    public void deleteRecord(@RequestBody AccessRecord accessRecord) {recordService.deleteRecord(accessRecord);}

}
